/* -------------------------------------------------------------------
 GeoVISTA Center (Penn State, Dept. of Geography)
 Java source file for the class LayerPoint
 Copyright (c), 2002, GeoVISTA Center
 Licensed under Simplified BSD License
 Original Author: Frank Hardisty
 $Author: hardisty $
 $Id: LayerPoint.java,v 1.3 2004/05/05 17:23:10 hardisty Exp $
 $Date: 2004/05/05 17:23:10 $
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc.,
 -------------------------------------------------------------------   */



package  edu.psu.geovista.app.map;

import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
/**
 * put your documentation comment here
 */
public class LayerPoint extends LayerShape {

  private Point2D[] originalPoints;


    /*
     * selectionX1 is expected to be less than selectionX2, same with Y1 and y2
     */
    public void findSelection (int selectionX1, int selectionX2, int selectionY1,
            int selectionY2) {
    }

    /*
     * selectionX1 is expected to be less than selectionX2, same with Y1 and y2
     */
    public void findSelectionShift (int selectionX1, int selectionX2, int selectionY1,
            int selectionY2) {
    }

    public int findIndication(int x, int y) {return Integer.MIN_VALUE;}
         /**
         * sets the points that the layer will use to draw from
         * these are assumed to be in user space
         * @param originalPoints
         */
        public void setOriginalPoints (Point2D[] originalPoints) {
                this.originalPoints = originalPoints;
        }
        /**
         * retrieves the points
         * @param originalPoints
         */
        public Point2D[] getOriginalPoints () {
                return this.originalPoints;
        }

        public Point2D[] shapesToPoints(Shape[] shapes){
          Point2D[] points = new Point2D.Double[shapes.length];
          for (int i = 0; i < shapes.length; i++) {
            Point2D pnt = new Point2D.Double();
            Shape shp = shapes[i];
            PathIterator path = shp.getPathIterator(null);
            double[] seg = new double[6];
            int segType = path.currentSegment(seg);
            if (segType != path.SEG_MOVETO) {
              throw new IllegalArgumentException("LayerPoint.shapesToPoints expects only PathIterator.SEG_MOVETO segments");
            }
            pnt.setLocation(seg[0],seg[1]);
            points[i] = pnt;
          }

          return points;
        }

        public Shape[] pointsToShapes(Point2D[] points){
          Shape[] shapes = new Shape[points.length];
          for (int i = 0; i < shapes.length; i++) {
            GeneralPath shp = new GeneralPath();
            Point2D pnt = points[i];
            shp.moveTo((float)pnt.getX(),(float)pnt.getY());
            shapes[i] = shp;
          }

          return shapes;
        }


        public Shape[] findShapesForPoints(Point2D[] points){
          Shape[] shapes = new Shape[points.length];
          float shapeSize = 2f;
          float half = shapeSize / 2f;
          for (int i = 0; i < shapes.length; i++) {
            Point2D pt = points[i];

            Ellipse2D eli= new Ellipse2D.Float((float)pt.getX() - half,(float)pt.getY() - half,shapeSize,shapeSize);

            shapes[i] = eli;
          }

          return shapes;
        }
}